<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
use Hyperf\Database\Model\Builder;

/**
 */
class LotteryPrize extends Model
{

    use SelectTrait;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'lottery_prize';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name','img','sort','batch_id','type','probability','status','add_time','update_time','is_del'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $guarded=['id'];
    protected $casts = [
        'add_time'=>'datetime:Y-m-d H:i:s',
        'update_time'=>'datetime:Y-m-d H:i:s',
    ];

    const CREATED_AT = 'add_time';
    const UPDATED_AT = 'update_time';

    public $timestamps = true;
    protected $dateFormat = 'U';
    protected function boot(): void
    {   
        $this->bootTraits();

        //model 软删除过滤 避免每次查询都添加is_del条件 去除条件添加withoutGlobalScope
        // $this->addGlobalScope('is_del', function(Builder $builder) {
        //     $builder->where($this->table.'.is_del',1);
        // });
        // var_dump($columns);
    }



    public function scopeOfNotDel($query){
        return $query->where($this->table.'.is_del',1);
    }

    //映射status
   public function getStatusMappingAttribute(){
        $val='';
        switch($this->attributes['status']){
            case 1:$val='正常';break;
            case 2:$val='禁用';break;
            default:break;
        }
        return $val;
    }

    //一对一获取红包批次
    public function couponBatch(){
        return $this->hasOne(CouponBatch::class,'id','batch_id');
    }
    
}